package com.example.sms_emoticon_library;


import java.io.IOException;
import java.io.Serializable;

import com.example.model.*;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;



public class PictureSms extends Activity {

	ImageView imgPicture;
	TextView txtSend,txtBack;
	EditText edtText;
	Intent intentFuntion;
	Bundle dataLoadImage;
	Bitmap scaled, bmSmsPicture;
	String picturePath;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_picture_sms);
		imgPicture = (ImageView) findViewById(R.id.imgPictureSms);
	    txtSend = (TextView) findViewById(R.id.txtSend);
	    txtBack = (TextView) findViewById(R.id.txtBack);
	    edtText = (EditText) findViewById(R.id.edtText);
	    
		intentFuntion= getIntent();
		dataLoadImage=getIntent().getExtras();
		
		// bmSmsPicture= dataLoadImage.getParcelable("abc");
		
		//String encodedImage= dataLoadImage.getString("encodedImage");
		//byte[] a = encodedImage.getBytes();
		//BitmapFactory.Options bo= new BitmapFactory.Options();
		//bo.inSampleSize=2;
		//Bitmap image= BitmapFactory.decodeByteArray(a, 0, a.length,bo);
		
		picturePath= dataLoadImage.getString("picturePath");
		bmSmsPicture= BitmapFactory.decodeFile(picturePath);
		
		int nh = (int) ( bmSmsPicture.getHeight() * (512.0 / bmSmsPicture.getWidth()) );
		scaled = Bitmap.createScaledBitmap(bmSmsPicture, 512, nh, true);
		imgPicture.setImageBitmap(scaled);
		
		txtSend.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			   SmsPicture smsPic =  new SmsPicture();
			   smsPic.set_bitmap(bmSmsPicture);
			   smsPic.set_text(edtText.getText().toString());
			   ParcelableSmsPicture parSmsPic= new ParcelableSmsPicture(smsPic);
			   Bundle  bund = new Bundle();
			   
			   //bund.putSerializable("SmsPic", (Serializable) smsPic);
			   //bund.putParcelable("ParSmsPic", parSmsPic);
			   bund.putString("text", edtText.getText().toString());
			   bund.putString("path", picturePath);
			   intentFuntion.putExtra("DATA", bund);
			   setResult(FragmentFuntions.RESULT_SENT_PIC, intentFuntion);
			   finish();
			  
			
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.picture_sms, menu);
		return true;
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		super.onBackPressed();
		
	}
	
	

}
